package com.serve.oa.service.impl;

import com.serve.oa.entity.ComOrganization;
import com.serve.oa.entity.comUser;
import com.serve.oa.mapper.ComOrganizationMapper;
import com.serve.oa.service.ComOrganizationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author __tyw
 * @since 2022-12-06
 */
@Service
public class ComOrganizationServiceImpl extends ServiceImpl<ComOrganizationMapper, ComOrganization> implements ComOrganizationService {

    @Autowired
    ComOrganizationMapper comOrganizationMapper;

    public  List<comUser> getOrgeUser(Long id){

        List<comUser> list = comOrganizationMapper.getOrgeUser(id);
        List<Map> list1 = comOrganizationMapper.getManId(id);

        list.forEach(i->{
            i.setIsMan(false);
            list1.forEach(a->{
                //System.out.println(a.get("user_id") == i.getUserId());
                //System.out.println(i.getUserId());
                if(a.get("user_id") == i.getUserId()){
                    i.setIsMan(true);
                    i.setManId((Long) a.get("id"));
                }
            });

        });
        return list;
    }

    @Override
    @Transactional
    public String eidtOrgeUser(Long id , List<Long> params) {
        //删除1
        comOrganizationMapper.batchDelete(id);
        //删除1
        //comOrganizationMapper.batchDeletes(id);
        if(params != null && !params.isEmpty()){
        comOrganizationMapper.addDeletes(id , params);
        }




       return "操作成功";
    }

    @Override
    public int setMan(Map<String, Long> obj) {
      return  comOrganizationMapper.addMan(obj);

    }

    @Override
    public void delman(Long id) {
        comOrganizationMapper.delMan(id);
    }

    @Override
    public List<Integer> gerManUserByuserId(String fqr) {
        //System.out.println("22131");
        List<Map> a  =  comOrganizationMapper.gerManUserByuserId(fqr);
        List<Integer>  SS =new ArrayList<Integer>();
        a.forEach(i->{
            //System.out.println(i.get("user_id"));
            SS.add(Integer.valueOf(i.get("user_id").toString()));
        });
        int[] asd ={};


        return SS;
    }

    @Override
    public List<Map> getUserIdBYorgid(Long id) {
        //System.out.println(11922);
        return comOrganizationMapper.getManId(id);
    }

}
